import os
import os.path
import sys
import argparse

parser = argparse.ArgumentParser(description='打印文件夹目录结构')
parser.add_argument('path', type=str, help='待打印的文件夹')
parser.add_argument('depth', type=int, help='目录深度')
parser.add_argument('file_cts_limit', type=int, default=sys.maxsize, help='每个文件夹下最多显示的文件数')

args = parser.parse_args()

def dfs_showdir(path, depth, cur_depth=0, file_cts_limit=sys.maxsize):
    if depth == 0:
        print("root:[" + path + "]")
    if depth <= cur_depth:
        return
    
    file_cts = 0
    for item in os.listdir(path):
        # print(file_cts, file_cts_limit)
        if '.git' not in item:
            # print("| " * cur_depth + "+--" + item)
            newitem = path +'/'+ item
            if os.path.isdir(newitem):
                print("| " * cur_depth + "+--" + item)
                dfs_showdir(newitem, depth, cur_depth + 1, file_cts_limit)
            else:
                file_cts += 1
                if file_cts > file_cts_limit:
                    continue
                elif file_cts == file_cts_limit:
                    print("| " * cur_depth + "+--" + '...')
                else:
                    print("| " * cur_depth + "+--" + item)
                
                
if __name__ == '__main__':
    print(args)
    dfs_showdir(args.path, args.depth, file_cts_limit=args.file_cts_limit)

